/************** init.html **************/

function editHandle_role(code) {
	var url = create_url('organRole-editHandle');
	var parm = {'code':code};
	$.colorbox({overlayClose:false, href:url, data:parm, close:'[关闭]', width:'800px', height:'600px', open:true});
}

function queryRole_role(page) {
	sys_loading();
	var parm = $('#queryRoleForm').serialize() + (page != null ? ('&page=' + page) : '');
	var url = create_url('organRole-query');
	sys_record_parm('organRole',parm);
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_loading_close();
			$('#roleResultList').html(result);
		}
	});
}


function deleteRole_role(code) {
	$.Zebra_Dialog('确认要删除 角色信息吗？',{
	'type': 'question',
	'title': '警告' ,
	'buttons':[
       {caption:'确认',callback:function() {
			var url = create_url('organRole-deleteRole');
			var parm = {'code':code};
			sys_submiting();
			$.ajax({type:'POST', url:url, data:parm,
				success: function(result) {
					sys_submiting_close();
						queryRole_role();
			}
			})}},
       {caption:'取消',callback:function(){}}
		]
	});
}

/**
 * 通过机构编号查询出该机构和该机构所有的子机构
 */
function selectOrgan_role(oc, on) {
	var url = create_url('emp-aidInit');
	var parm = {'oc':oc, 'on':on};
	$.colorbox({overlayClose:false, href:url, data:parm, close:'[关闭]', width:'800px', height:'600px', open:true});
}
/************edit.html****************/


function saveRole_role() {
	var parm = $('#editRoleForm').serialize();
	var url = create_url('organRole-save');
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_submiting_close();
			if (result == 'success') {
				sys_load_handle('organRole');
			}else if(result == 'name_same') {
				sys_msg('有相同的角色了！！');
			} else {
				sys_msg('操作失败!');
			}
		}
	});
}


function selectOrgan_role(oc, on) {
	var url = create_url('emp-aidInit');
	var parm = {'oc':oc, 'on':on};
	$.colorbox({overlayClose:false, href:url, data:parm, close:'[关闭]', width:'800px', height:'600px', open:true});
}


//选择操作
function selectedOrganType_role(cbCode) {
	var cb = $('#' + cbCode);
	$('input[parentCode="' + cbCode + '"]').each(function(e) {
		
		if (cb.attr('checked') == 'checked' || cb.attr('checked') || cb.prop('checked'))
			$(this).attr('checked', 'checked');
		else 
			$(this).removeAttr('checked');

		selectedOrganType_role($(this).attr('id'));
	});

	if (cb.prop('checked')) {
		var parentCb = $('#' + cb.attr('parentCode'));
		while (true) {
			if (null == parentCb || 'undefined' == parentCb || '' == parentCb.attr('id') || null == parentCb.attr('id'))
				break;
			parentCb.prop('checked', true);
			parentCb = $('#' + parentCb.attr('parentCode'));
		}
	} else {
		var flag = true;
		var parentCode = cb.attr('parentCode');
		while (true) {
			if (null == parentCode || '' == parentCode)
				break;

			$('input[parentCode="' + parentCode + '"]').each(
				function() {
					if ($(this).prop('checked'))
						flag = false;
			});
			if (flag) {
				$('#' + parentCode).prop('checked', false);
				parentCode = $('#' + parentCode).attr('parentCode');
			} else {
				break;
			}
		}
	}

}




function showOrHide_role(btn, div) {
	$('#' + div).slideToggle("slow");
}